package com.yingxin.yxerp.task;

import com.yingxin.yx.framework.security.userdetails.AccountUserDetailsService;
import com.yingxin.yx.framework.user.dto.PermissionDto;
import com.yingxin.yx.framework.user.dto.UserDto;
import com.yingxin.yx.framework.web.req.RequestInfo;
import com.yingxin.yxerp.module.organization.entity.User;
import com.yingxin.yxerp.module.organization.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author fanchao
 */
@Slf4j
@Service
public class UserDetailsService implements AccountUserDetailsService {

    @Autowired
    private IUserService userService;

    @Override
    public UserDetails loadUserByUsername(String username) throws AuthenticationException {
        return null;
    }

    @Override
    public List<PermissionDto> permissions(String userId) throws AuthenticationException {
        return null;
    }

    @Override
    public void loginSuccessLog(UserDto user, RequestInfo requestInfo) {
    }

    @Override
    public UserDto getUserInfo(String id) {
        User user = userService.getById(id);
        UserDto userDto = new UserDto();
        BeanUtils.copyProperties(user,userDto);
        return userDto;
    }

    @Override
    public void lockUser(String username) {
    }

    /**
     * 记录用户登录错误
     */
    @Override
    public void saveLoginErrorLog(String userName, String password, String loginIp, String pcOrApp){

    }

}
